package reno.activity.dao;

import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.springframework.stereotype.Repository;
import reno.activity.common.HibernateUtils;
import reno.activity.eo.ActivityEntity;
import reno.activity.eo.ActivitydetailEntity;

import java.util.List;

@Repository
public class ActivityDao {
    public ActivityEntity getActivityInfo(Long activityid) {
        String sql = "select *,'' open from activity a where a.activityid = ?";
        Session session = HibernateUtils.getSession();
        NativeQuery<ActivityEntity> query = session.createNativeQuery(sql.replace("?",activityid.toString()),ActivityEntity.class);
        List<ActivityEntity> activityEntityList = query.list();
        session.close();
        if (activityEntityList.size() >= 1) {
            return activityEntityList.get(0);
        }else{
            return null;
        }
    }

    public List<ActivitydetailEntity> getActivityDetailInfo(Long activityid) {
        String sql = "select * from activitydetail a where a.activityid = ?";
        Session session = HibernateUtils.getSession();
        NativeQuery<ActivitydetailEntity> query = session.createNativeQuery(sql.replace("?",activityid.toString()),ActivitydetailEntity.class);
        List<ActivitydetailEntity> activitydetailEntityList = query.list();
        session.close();
        return activitydetailEntityList;
    }
}
